var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order_type: 0,
    recordsData: [],
    page: 1,
    total: 0,
    finished: false,
    tabs: [{
      name: "全部",
      value: 0
    },{
      name: "商城订单",
      value: 1
    },{
      name: "非商城订单",
      value: 2
    }],
    love_name: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.getData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onClickTab(event) {
    this.setData({
      order_type: event.detail.name,
      recordsData: [],
      page: 1,
      total: 0,
      finished: false,
    })
    this.getData();
  },
  getData() {
    if (this.data.finished) return;
    app._getNetWork({
      url: app.getNetAddresss("plugin.third-logistics.frontend.modules.scan.controllers.records.index"),
      data: {
        page: this.data.page,
        order_type: this.data.order_type
      },
      success: (respone) => {
        if (respone.data.result !== 1) {
          wx.showToast({
            title: respone.data.msg,
          });
          return false;
        }
        let res = respone.data.data;
        let finished = false;
        let recordsData = [];
        let total = 1;
        recordsData = this.data.recordsData.concat(res.page_list.data);
        if (res.page_list.data.length === 0 || res.page_list.data.length < res.page_list.per_page || res.page_list.current_page === res.page_list.last_page) {
          finished = true;
        }
        total = res.page_list.total;
        this.setData({
          finished,
          recordsData,
          page: ++this.data.page,
          total,
          love_name: res.otherParams.love_name
        });
      }
    });
  },
})